<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <link rel="shortcut icon" href="logo.png" type="image/x-icon"/>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/global.css">
    <link rel="stylesheet" href="css/home_v3.css"/>
</head>
<body>

<div class="wrap clear news_content" id="main">
    <!--左边-->
    <div class="left left-box">
        <!--banner-->
        <div class="yhome-banner">
            <a href="" class="yhb-big left">
                <i>行业</i>
                <img src="http://p9.pstatp.com/list/640x360/2ecd00018d26750870f3" alt="">
                <span class="over">网红“什么七七”清纯美照，清新可人er</span>
            </a>
            <a href="" class="yhb-small right">
                <i>娱乐</i>
                <img src="http://p1.pstatp.com/list/272x178/2edc000214935e8e9a5a" alt="">
                <span class="over">古筝女主播大汇总</span>
            </a>
            <a href="" class="yhb-small yhb-small2 right">
                <i>视频</i>
                <img src="http://p3.pstatp.com/list/272x178/2ece0000dbdbfbd7dd46" alt="">
                <span class="over">直击撒贝宁和妻子的甜蜜爱情，一路被祝福</span>
            </a>
        </div>
        <!--新闻-->
        <div id="home-list">
            <div class="tab-bar">
                <ul class="clear">
                    <li class="active"><a href="javascript:void(0);">全&nbsp;&nbsp;部</a></li>
                    <li><a href="javascript:void(0);">资&nbsp;&nbsp;讯</a></li>
                    <li><a href="javascript:void(0);">行&nbsp;&nbsp;业</a></li>
                    <li><a href="javascript:void(0);">图&nbsp;&nbsp;集</a></li>
                    <li><a href="javascript:void(0);">视&nbsp;&nbsp;频</a></li>
                    <li><a href="javascript:void(0);">游&nbsp;&nbsp;戏</a></li>
                </ul>
            </div>
            <!--全部-->
            <div class="list-main" data-bind="template:{name:'data-template',foreach:data1}"></div>
            <div class="list-main" data-bind="template:{name:'data-template',foreach:data2}"></div>
            <div class="list-main" data-bind="template:{name:'data-template',foreach:data3}"></div>
            <div class="list-main" data-bind="template:{name:'data-template',foreach:data4}"></div>
            <div class="list-main" data-bind="template:{name:'data-template',foreach:data5}"></div>
            <div class="list-main" data-bind="template:{name:'data-template',foreach:data6}"></div>
            <script type="text/html" id="data-template">
                <div data-bind="template:{name:'operation',foreach:data}"></div>
            </script>
            <!--根据不同类型跳转不同模版-->
            <script id="operation" type="text/html">
                <!--视频-->
                <div data-bind="if:type==4 || type==5 || type==10">
                    <div class="news-item clear">
                        <div class="left video-lcover">
                            <a data-bind="attr:{href:'/video/'+id+'.html'}" target="_blank">
                                <img class="cover-inner" data-bind="attr:{src:replaceImageSuffix(cover)}">
                                <img class="play-icon" src="images/play-icon.png" alt="">
                            </a>
                        </div>
                        <div class="right news-rbox normal">
                            <div class="rbox-inner">
                                <h3><a data-bind="attr:{href:'/video/'+id+'.html'}" target="_blank"><span
                                        data-bind="text:cutString(title,100)"></span></a></h3>
                                <p>
                                    <img class="u-avatar" data-bind="attr:{src:user.data.avator}">
                                    <span class="u-name" data-bind="text:user.data.username"></span>
                                    <b></b>
                                    <img class="view-count" src="images/play_count.png" alt="播放量">
                                    <span data-bind="text:view_count"></span>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
                <!--图集四张图-->
                <div data-bind="if:type==1 && pictures_count>3">
                    <!--<div data-bind="text:(function(){debugger})()" ></div>-->
                    <div class="news-item clear">
                        <div class="normal pic-news">
                            <h3><a data-bind="attr:{href:'/news/'+id+'.html'}" target="_blank"><span
                                    data-bind="text:cutString(title,100)"></span></a></h3>
                            <div class="img-list clear">
                                <div class="img-list-inner">
                                    <a data-bind="attr:{href:'/news/'+id+'.html'}" class="img-wrap" target="_blank"><img
                                            data-bind="attr:{src:replaceImageSuffix(pictures[0].src)}"></a>
                                    <a data-bind="attr:{href:'/news/'+id+'.html'}" class="img-wrap" target="_blank"><img
                                            data-bind="attr:{src:replaceImageSuffix(pictures[1].src)}"></a>
                                    <a data-bind="attr:{href:'/news/'+id+'.html'}" class="img-wrap" target="_blank"><img
                                            data-bind="attr:{src:replaceImageSuffix(pictures[2].src)}"></a>
                                    <a data-bind="attr:{href:'/news/'+id+'.html'}" class="img-wrap" target="_blank"><img
                                            data-bind="attr:{src:replaceImageSuffix(pictures[3].src)}"></a>
                                </div>
                            </div>
                            <p>
                                <img class="u-avatar" data-bind="attr:{src:user.data.avator}">
                                <span class="u-name" data-bind="text:user.data.username"></span>
                                <b></b>
                                <img class="view-count" src="images/view_count.png" alt="访问量">
                                <span data-bind="text:view_count"></span>
                            </p>
                        </div>
                    </div>
                </div>
                <!--新闻没有图-->
                <div data-bind="if:list_cover.length==0 && type==2">
                    <div class="news-item clear">
                        <div class="no-cover normal">
                            <h3><a data-bind="attr:{href:'/news/'+id+'.html'}" target="_blank"><span
                                    data-bind="text:cutString(title,100)"></span></a></h3>
                            <p>
                                <img class="u-avatar" data-bind="attr:{src:user.data.avator}">
                                <span class="u-name" data-bind="text:user.data.username"></span>
                                <b></b>
                                <img class="view-count" src="images/view_count.png" alt="访问量">
                                <span data-bind="text:view_count"></span>
                            </p>
                        </div>
                    </div>
                </div>
                <!--新闻一张图-->
                <div data-bind="if:list_cover.length>0 && list_cover.length<4">
                    <div class="news-item clear">
                        <div class="left news-lcover">
                            <a data-bind="attr:{href:'/news/'+id+'.html'}" target="_blank"><img
                                    data-bind="attr:{src:replaceImageSuffix(cover)}"></a>
                        </div>
                        <div class="right news-rbox normal">
                            <div class="rbox-inner">
                                <h3><a data-bind="attr:{href:'/news/'+id+'.html'}" target="_blank"><span
                                        data-bind="text:cutString(title,100)"></span></a></h3>
                                <p>
                                    <img class="u-avatar" data-bind="attr:{src:user.data.avator}">
                                    <span class="u-name" data-bind="text:user.data.username"></span>
                                    <b></b>
                                    <img class="view-count" src="images/view_count.png" alt="访问量">
                                    <span data-bind="text:view_count"></span>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
                <!--新闻4张图-->
                <div data-bind="if:list_cover.length>=4">
                    <!--断点调试-->
                    <!--<div data-bind="text:(function(){debugger})()" ></div>-->
                    <div class="news-item clear">
                        <div class="normal pic-news">
                            <h3><a data-bind="attr:{href:'/news/'+id+'.html'}" target="_blank"><span
                                    data-bind="text:cutString(title,100)"></span></a></h3>
                            <div class="img-list clear">
                                <div class="img-list-inner">
                                    <a data-bind="attr:{href:'/news/'+id+'.html'}" class="img-wrap" target="_blank"><img
                                            data-bind="attr:{src:replaceImageSuffix(list_cover[0].cover)}"></a>
                                    <a data-bind="attr:{href:'/news/'+id+'.html'}" class="img-wrap" target="_blank"><img
                                            data-bind="attr:{src:replaceImageSuffix(list_cover[1].cover)}"></a>
                                    <a data-bind="attr:{href:'/news/'+id+'.html'}" class="img-wrap" target="_blank"><img
                                            data-bind="attr:{src:replaceImageSuffix(list_cover[2].cover)}"></a>
                                    <a data-bind="attr:{href:'/news/'+id+'.html'}" class="img-wrap" target="_blank"><img
                                            data-bind="attr:{src:replaceImageSuffix(list_cover[3].cover)}"></a>
                                </div>
                            </div>
                            <p>
                                <img class="u-avatar" data-bind="attr:{src:user.data.avator}">
                                <span class="u-name" data-bind="text:user.data.username"></span>
                                <b></b>
                                <img class="view-count" src="images/view_count.png" alt="访问量">
                                <span data-bind="text:view_count"></span>
                            </p>
                        </div>
                    </div>
                </div>

            </script>
        </div>
    </div>
</div>
<!--全部-->
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/knockout-3.4.2.js"></script>
<script type="text/javascript" src="js/dropload.min.js"></script>
<script type="text/javascript">
    $(function () {
        // 页数
        var tab1LoadEnd = false;
        var tab2LoadEnd = false;
        var tab3LoadEnd = false;
        var tab4LoadEnd = false;
        var tab5LoadEnd = false;
        var tab6LoadEnd = false;
        var page1 = 1;
        var page2 = 1;
        var page3 = 1;
        var page4 = 1;
        var page5 = 1;
        var page6 = 1;
        var selectedTab = 0;
        var viewMode = {
            data1: ko.observableArray(),
            data2: ko.observableArray(),
            data3: ko.observableArray(),
            data4: ko.observableArray(),
            data5: ko.observableArray(),
            data6: ko.observableArray(),
        };
        //下拉加载
        var dropload = $('#home-list').dropload({
            scrollArea: window,
            domDown: {
                domClass: 'list-loading',
                domRefresh: '<img src="images/loading.gif" alt="正在加载中"> 正在加载中',
                domLoad: '<img src="images/loading.gif" alt="正在加载中"> 正在加载中',
                domNoData: '<p class="list-loading">暂无数据</p>'
            },
            loadDownFn: function (me) {
                console.log(selectedTab);
                if (selectedTab == 0) {
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/200/article/rand/1?page=' + page1,
                        dataType: 'json',
                        success: function (data) {
                            console.log(1111);
                            console.log(data);
                            page1++;
                            setTimeout(function () {
                                viewMode.data1.push(data);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (selectedTab == 1) {
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/201/article/rand/1?page=' + page2,
                        dataType: 'json',
                        success: function (data) {
                            page2++;
                            setTimeout(function () {
                                viewMode.data2.push(data);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (selectedTab == 2) {
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/202/article/rand/1?page=' + page3,
                        dataType: 'json',
                        success: function (data) {
                            page3++;
                            setTimeout(function () {
                                viewMode.data3.push(data);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (selectedTab == 3) {
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/203/article/rand/1?page=' + page4,
                        dataType: 'json',
                        success: function (data) {
                            page4++;
                            setTimeout(function () {
                                viewMode.data4(data);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (selectedTab == 4) {
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/204/article//rand1?page=' + page5,
                        dataType: 'json',
                        success: function (data) {
                            page5++;
                            setTimeout(function () {
                                viewMode.data5(data);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                } else if (selectedTab == 5) {
                    $.ajax({
                        type: 'GET',
                        url: 'http://www.youkb.com/api/v1/pc/categories/205/article/rand/1?page=' + page6,
                        dataType: 'json',
                        success: function (data) {
                            page6++;
                            setTimeout(function () {
                                viewMode.data6(data);
                                // 每次数据加载完，必须重置
                                me.resetload();
                            }, 100);
                        },
                        error: function (xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                }
            }
        })
        ko.applyBindings(viewMode);
        dropload.search();
        // ******Tab切换******************************************
        $('.tab-bar ul li').click(function () {
            var $this = $(this);
            selectedTab = $this.index();
            $this.addClass('active').siblings().removeClass('active');
            $('.list-main').eq(selectedTab).show().siblings('.list-main').hide();
            // 如果选中菜单一
            if (selectedTab == '0') {
                // 如果数据没有加载完
                if (!tab1LoadEnd) {
                    // 解锁
                    dropload.unlock();
                    dropload.noData(false);
                } else {
                    // 锁定
                    dropload.lock('down');
                    dropload.noData();
                }
                // 如果选中菜单二
            } else if (selectedTab == '1') {
                if (!tab2LoadEnd) {
                    // 解锁
                    dropload.unlock();
                    dropload.noData(false);
                } else {
                    // 锁定
                    dropload.lock('down');
                    dropload.noData();
                }
            } else if (selectedTab == '2') {
                if (!tab3LoadEnd) {
                    // 解锁
                    dropload.unlock();
                    dropload.noData(false);
                } else {
                    // 锁定
                    dropload.lock('down');
                    dropload.noData();
                }
            } else if (selectedTab == '3') {
                if (!tab4LoadEnd) {
                    // 解锁
                    dropload.unlock();
                    dropload.noData(false);
                } else {
                    // 锁定
                    dropload.lock('down');
                    dropload.noData();
                }
            } else if (selectedTab == '4') {
                if (!tab5LoadEnd) {
                    // 解锁
                    dropload.unlock();
                    dropload.noData(false);
                } else {
                    // 锁定
                    dropload.lock('down');
                    dropload.noData();
                }
            } else if (selectedTab == '5') {
                if (!tab6LoadEnd) {
                    // 解锁
                    dropload.unlock();
                    dropload.noData(false);
                } else {
                    // 锁定
                    dropload.lock('down');
                    dropload.noData();
                }
            }
            // 重置
            dropload.resetload();
            dropload.search();
        });
    });

    //***字数控制*************************************************
    function cutString(str, len) {
        //length属性读出来的汉字长度为1
        if (str.length * 2 <= len) {
            return str
        }
        var strlen = 0
        var s = ""
        for (var i = 0; i < str.length; i++) {
            s = s + str.charAt(i)
            if (str.charCodeAt(i) > 128) {
                strlen = strlen + 2
                if (strlen >= len) {
                    return s.substring(0, s.length - 1) + "…"
                }
            } else {
                strlen = strlen + 1
                if (strlen >= len) {
                    return s.substring(0, s.length - 2) + "…"
                }
            }
        }
        return s
    }
    //替换图片后缀
    function replaceImageSuffix(cover) {
        if (cover.indexOf("-app.thumbnail") > 0) {
            return cover.replace("-app.thumbnail", "-web.thum");
        } else {
            return cover + '-web.thum';
        }
    }
</script>
</body>
</html>